package com.lagou.mr;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * reduce类
 */
public class SortReducer extends Reducer<LongWritable, NullWritable,LongWritable,LongWritable> {
    //定义行号 一开始为1
    LongWritable lineNum = new LongWritable(1);
    @Override
    protected void reduce(LongWritable key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        //取出每一个key
        for (NullWritable value : values) {
            //在这里不用进行排序了，因为map那边的key已经排过序了
            //reduece输出的key是行号，value才是要排序的数字
            context.write(lineNum,key);
            //行号+1
            lineNum = new LongWritable(lineNum.get() + 1);
        }
    }
}
